﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.Model;
using IHISCETeim.Library;
using IHISCETeim.BLL;
using System.Data;
namespace IHISCETeim.Web.MachineSys.UserModel
{
    public partial class UFXOC55NSLEdit : PageBase
    {
        protected override string DWZRef
        {
            get { return "UFXCompletingCheckList"; }
        }


        /// <summary>
        /// 需查看的机号
        /// </summary>
        protected string SerialNumber
        {
            get
            {
                return GetRequestValue<string>("SerialNumber");
            }
        }

        protected int Id
        {
            get
            {
                return GetRequestValue<int>("Id",0);
            }
        }
        private UFXCompletingCheckInfo _obj;
        protected UFXCompletingCheckInfo obj
        {
            get
            {
                if (_obj == null)
                    _obj = UFXCompletingCheckController.GetById(Id);
                return _obj;
                //OMenuController.ge
            }
        }

        private List<UFXCompletingCheckNGInfo> _ngList = null;
        protected List<UFXCompletingCheckNGInfo> ngList
        {
            get {
                if (_ngList == null)
                    _ngList = UFXCompletingCheckController.UFXCompletingCheckNG_GetById(Id);
                return _ngList;
            }
        }
        private SerializableDictionary<string, bool> _QTJDJXMLDict = null;
        /// <summary>
        /// 启动前点检所有的项
        /// </summary>
        protected SerializableDictionary<string, bool> QTJDJXMLDict
        {
            get
            {
                if (_QTJDJXMLDict == null)
                {
                    _QTJDJXMLDict = XmlSerializerHelper.Deserialize<SerializableDictionary<string, bool>>(obj.QDQDJItem);
                }
                return _QTJDJXMLDict;
            }
        }

        private SerializableDictionary<string, XRJCItem> _XRJCDict = null;
        /// <summary>
        /// 性能检查所有的项
        /// </summary>
        protected SerializableDictionary<string, XRJCItem> XRJCDict
        {
            get
            {
                if (_XRJCDict == null)
                {
                    try
                    {
                        _XRJCDict = XmlSerializerHelper.Deserialize<SerializableDictionary<string, XRJCItem>>(obj.XNJCItem);
                       // if (_XRJCDict.Count() <= 0)
                       // {
                           // _XRJCDict = new SerializableDictionary<string, XRJCItem>(CompleteCheckXMLHelper.XRJCDict);
                        //SerializableDictionary<string, float> tempdic = XmlSerializerHelper.Deserialize<SerializableDictionary<string, float>>(CompleteCheckXMLHelper.GetXRJCXMLStr());

                        foreach (var x in CompleteCheckXMLHelper.XRJCDict)
                            {
                                //XRJCItem tempitem = new XRJCItem();
                                //tempitem.Key = x.Key;
                                //tempitem.Value = x.Value.ToString();
                                //tempitem.NGValue = "OK";

                                if (!_XRJCDict.ContainsKey(x.Key))
                                {
                                    XRJCItem tempitem = new XRJCItem();
                                    tempitem.Key = x.Key;
                                    tempitem.Value = "";
                                    tempitem.NGValue = "OK";
                                    _XRJCDict.Add(x.Key, tempitem);
                                }
                               

                               

                                //tempdic[x.Key] = HttpContext.Current.Request.GetRequestValue<float>(x.Key);
                            }
                       // }
                    }
                    catch
                    {
                        /**/

                    }
                }
                return _XRJCDict;
            }
        }


        private SerializableDictionary<string, bool> _GZQRDict = null;
        /// <summary>
        /// 工作确认所有的项
        /// </summary>
        protected SerializableDictionary<string, bool> GZQRDict
        {
            get
            {
                if (_GZQRDict == null)
                {
                    _GZQRDict = XmlSerializerHelper.Deserialize<SerializableDictionary<string, bool>>(obj.GZQRItem);
                    foreach (var x in CompleteCheckXMLHelper.GZQRDict)
                    {
                        if (!_GZQRDict.ContainsKey(x.Key))
                        {
                            _GZQRDict.Add(x.Key,true);
                        }
                    }
                }
                return _GZQRDict;
            }
        }

        protected string GetNGSelect(string controlName)
        {
            string selectHtml = "";//;"<select name=\"NG_铁履H前10m\"><option value=\"OK\" selected>OK</option><option value="NG->OK">NG->OK</option><option value="NG">NG</option></select>";
            string[] ngItme = new string[] { "NG", "NG->OK", "OK" };
            foreach (string item in ngItme)
            {
                string c = XRJCDict[controlName].NGValue == item ? "selected" : "";
                selectHtml += string.Format("<option value=\"{0}\" {1}>{0}</option>", item, c);
            }
            return string.Format("<select name=\"NG_{1}\">{0}</select>", selectHtml, controlName);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "edit")
            {
                addmenu();
               
            }
            try
            {
                
                this.rpDJNGItem.DataSource = ngList.FindAll(x => x.Type=="txt");
                this.rpDJNGItem.DataBind();
            }
            catch { }
        }

        protected UFXCompletingCheckNGInfo GetImgItm(string key)
        {
            UFXCompletingCheckNGInfo itm = ngList.Find(e => e.WT == key);
            if (itm == null)
                return new UFXCompletingCheckNGInfo();
            return itm;    
        }
       
        protected virtual void addmenu()
        {
            addmenu("55NSL");
            
            
        }
        protected void addmenu(string MachineType)
        {
           // string X = CompleteCheckXMLHelper.GetGZQRXMLStr();
        
            UFXCompletingCheckInfo objedit = Request.SerializableObject<UFXCompletingCheckInfo>();
            objedit.CCID = Id;
            objedit.QDQDJItem = CompleteCheckXMLHelper.GetQTJDJXMLStr();
            objedit.XNJCItem = CompleteCheckXMLHelper.GetXRJCXMLStr();
            objedit.GZQRItem = CompleteCheckXMLHelper.GetGZQRXMLStr();
            objedit.MachineType = MachineType;
            objedit.CreateDate = obj.CreateDate;

            string[] TypeS = GetRequestValue<string>("Type", "").Split(new char[] { ',' });
            string[] WTS = GetRequestValue<string>("WT", "").Split(new char[] { ',' });
            string[] YYFXS = GetRequestValue<string>("YYFX", "").Split(new char[] { ',' });
            string[] JGS = GetRequestValue<string>("JG", "").Split(new char[] { ',' });
            string[] OKS = GetRequestValue<string>("OK", "").Split(new char[] { ',' });
            string[] QRS = GetRequestValue<string>("QR", "").Split(new char[] { ',' });
            List<UFXCompletingCheckNGInfo> ngitems = new List<UFXCompletingCheckNGInfo>();

            for (int index = 0; index < TypeS.Count(); index++)
            {
                UFXCompletingCheckNGInfo ngitem = new UFXCompletingCheckNGInfo();
                if (!string.IsNullOrEmpty(TypeS[index]))
                {
                    ngitem.Type = TypeS[index];
                    ngitem.WT = WTS[index];
                    ngitem.YYFX = YYFXS[index];
                    ngitem.JG = JGS[index];
                    ngitem.OK = OKS[index];
                    ngitem.QR = QRS[index];
                    ngitems.Add(ngitem);
                }
            }
            //obj.CheckDate=
            this.AddLog(Permission.修改, obj, objedit);
            if (UFXCompletingCheckController.Update(objedit, ngitems))
                SuccessJson("修改成功", DWZRef);
            else
                ErrorJson("修改失败");


        }
    }
}